package com.sino.operation.commons.response;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;


public class CenterResponseEntity<T> {

    @JsonProperty("RESULT_CODE")
    private Integer code;
    @JsonProperty("RESULT_MESSAGE")
    private String msg;
    @JsonProperty("RESULT_DATA")
    private T data;

    public CenterResponseEntity() {
    }

    public CenterResponseEntity(Integer code, String msg, T data){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }


    public static CenterResponseEntity<?> build(){
        CenterResponseEntity<?> re = new CenterResponseEntity<>();
        re.setCode(200);
        re.setMsg("访问成功");
        re.setData(null);
        return re;
    }

    public static CenterResponseEntity<?> buildError(){
        CenterResponseEntity<?> re = new CenterResponseEntity<>();
        re.setCode(500);
        re.setMsg("访问失败");
        re.setData(null);
        return re;
    }

    public static  <S> CenterResponseEntity<List<S>> buildList(Class<S> type){
        CenterResponseEntity<List<S>> re = new CenterResponseEntity<>();
        re.setCode(200);
        re.setMsg("访问成功");
        re.setData(null);
        return re;
    }

    public static  <S> CenterResponseEntity<List<S>> buildListError(Class<S> type){
        CenterResponseEntity<List<S>> re = new CenterResponseEntity<>();
        re.setCode(500);
        re.setMsg("访问失败");
        re.setData(null);
        return re;
    }

    public static  <S> CenterResponseEntity<S> build(Class<S> type){
        CenterResponseEntity<S> re = new CenterResponseEntity<>();
        re.setCode(200);
        re.setMsg("访问成功");
        re.setData(null);
        return re;
    }

    public static  <S> CenterResponseEntity<S> buildError(Class<S> type){
        CenterResponseEntity<S> re = new CenterResponseEntity<>();
        re.setCode(500);
        re.setMsg("访问失败");
        re.setData(null);
        return re;
    }



    public Integer getCode() {
        return code;
    }

    public CenterResponseEntity<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public CenterResponseEntity<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public CenterResponseEntity<T> setData(T data) {
        this.data = data;
        return this;
    }
}
